package com.qiang.test05;

import java.util.concurrent.ConcurrentHashMap;

public class Demo03 {
    public static void main(String[] args) {
        ConcurrentHashMap<String,String> hm =
                new ConcurrentHashMap<>(100);
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 25; i++) {
                hm.put(i + "", i + "");
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 25; i < 51; i++) {
                hm.put(i + "", i + "");
            }
        });

        t1.start();
        t2.start();

        System.out.println("----------------------------");
//为了t1和t2能把数据全部添加完毕
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//0-0 1-1 ..... 50- 50
        for (int i = 0; i < 51; i++) {
            System.out.println(hm.get(i + ""));
        }//0 1 2 3 .... 50
    }
}
